
import MathTool from "../Tool/MathTool";
import MsgDispatcher, { MsgType } from "../Tool/MsgDispatcher";
import { EventTool } from "../Tool/EventTool";
import BaseAssetLoad from "./SubPackage/BaseAssetLoad";
import FBAssetLoader from "./SubPackage/FbAssetLoader";
import OppoAssetLoader from "./SubPackage/OppoAssetLoad";
import DefaultAssetLoader from "./SubPackage/DefaultAssetLoader";
import { WeChatShareData } from "./ResourceData";
import GameAdsManager, { PlatformType } from "../Ad/GameAdsManager";
import UIManager from "../UI/UIManager";
import WXAssetLoader from "./SubPackage/WXAssetLoader";
import QQAssetLoader from "./SubPackage/QQAssetLoader";

export default class ResourceLoader 
{

    protected  s_assetLoader:BaseAssetLoad=null;
   
    public  Init(): void 
    {
        EventTool.LogEvent("开始加载资源");
        GameAdsManager.Instance.InitAd();
        this.InitLoadPath();
    }


    protected  InitLoadPath()
    {
        console.log("InitLoadPath");
        switch (GameAdsManager.Instance.Platform) 
        {
            case PlatformType.FaceBook:
                this.s_assetLoader=new FBAssetLoader();
                break;
            case PlatformType.QQ:
                this.s_assetLoader=new QQAssetLoader();
                break;
            case PlatformType.WeChat:
                this.s_assetLoader=new WXAssetLoader();
                break;
            case PlatformType.Oppo:
                this.s_assetLoader=new OppoAssetLoader();
                break;
            default:
                this.s_assetLoader=new DefaultAssetLoader();
                break;
        }
        this.s_assetLoader.LoadAsset(this.LoadResources.bind(this));
       // UIManager.Instance.PushView(PushViewType.LoadingView);
    }


    public  LoadResources()
    {
      
    }


    protected  onLoadProgress(progress: number) 
    {
        let percent = Math.floor(progress * 100);
        console.log("onLoadProgress "+percent);
        this.s_assetLoader.OnLoadPregress(percent);
    }

    protected  onPreLoadFinish() 
    { 
        EventTool.LogEvent("资源加载完毕");
        MsgDispatcher.Send(MsgType.GameLoadOver.toString());
        Laya.LocalStorage.removeItem("leveldata");
        this.s_assetLoader.OnLoadFinished();
    }


    protected  s_wechatShareInfos:Array<WeChatShareData>=[];
    public  GetWxShareData()
    {
        if (this.s_wechatShareInfos.length<1) 
        {
          //  ResourceLoader.s_wechatShareInfos=Laya.loader.getRes(ResourceLoader.s_WeChatShareConfigJsonPath);
        }
        if (!this.CheckObjIsCanUSe( this.s_wechatShareInfos)) 
        {
          //  ResourceLoader.s_wechatShareInfos=Laya.loader.getRes(ResourceLoader.s_LocalWeChatShareConfigJsonPath);
        }
        return this.s_wechatShareInfos;
    }

    CheckObjIsCanUSe(obj)
    {
        if (obj==null||obj==undefined||obj=="undefined") 
        {
            return false;
        }
        return true;
    }
}